<?php
namespace app\modules\admin\controllers;
use Yii;
use yii\web\Controller;
use app\models\Login;
use yii\web\Cookie;
/**
 * Created by PhpStorm.
 * User: zhn
 * Date: 2015/8/18
 * Time: 10:03
 */
class LoginController extends Controller{
    public $layout='logins';
    public function actions(){
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
                'backColor'=>0x000000,//背景颜色
                'maxLength'=>4,  //�?大显示个�?
                'minLength' => 4,//�?少显示个�?
                'padding' => 3,//间距
                'height'=>30,//高度
                'width' =>70,  //宽度
                'foreColor'=>0xffffff,     //字体颜色
                'offset'=>4,        //设置字符偏移�? 有效�?
            ],
        ];
    }
    public function actionIndex(){
        $model=new Login();
        if($model->load(Yii::$app->request->post()) && $model->validate()){
            $user=$_POST['Login']['user'];
            $password=strtoupper(sha1($_POST['Login']['password']));
            $admins=$model->find()->where(['user'=>$user,'password'=>$password])->one();
            if($admins){
                /*$cookies_data=array(
                    'name'=>$admins['user'],
                    'value'=>date('Y-m-d'),
                );
                $cookies = Yii::$app->response->cookies;
                $cookies->add(new Cookie($cookies_data));*/
                $session=Yii::$app->session;
                if($session->isActive){
                }else{
                    $session->open();//开启session
                }
                $session['admin_id']=$admins['id'];
                $session['islogin']=1;
                $this->redirect(array('/admin/default/index'));
            }else{
                $this->redirect(['index']);
            }
        }
        return $this->render('index',['model'=>$model]);
    }
}
?>